import Vue from 'vue'
import { mapState } from 'vuex'
import { USER_INFO } from '@/store/mutation-types'
import { STable, Ellipsis } from '@/views/box/components'
import FilterConditions from './Filter'
import ListModal from './ListModal'
import { getFashionerSubStatus } from '@/api/box/member.js'

export const cusListMixin = {
  components: {
    FilterConditions,
    ListModal,
    STable,
    Ellipsis
  },
  props: {
    filter: {
      type: Object,
      default: {}
    },
    fashionerObj: {
      type: Object,
      default: {}
    },
    speReasonList: {
      type: Array,
      default: []
    },
    blackReasonList: {
      type: Array,
      default: []
    },
    paramTree: {
      type: Array,
      default: []
    },
    subType: {
      type: Array,
      required: false
    }
  },
  data () {
    return {
      selectedRowKeys: [],
      selectedRows: [],
      userInfo: Vue.ls.get(USER_INFO),
      mdl: null,
      modalType: '',
      modalVisible: false,
      confirmLoading: false,
      paginationProps: {
        total: 0,
        showTotal: total => `共有 ${total} 条数据`
        // onShowSizeChange: (current, pageSize) => this.changePageSize(current, pageSize)
      },
    }
  },
  computed: {
    ...mapState({
      customerStatusList: state => state.user.customerStatusList
    }),
    rowSelection () {
      return {
        selectedRowKeys: this.selectedRowKeys,
        onChange: this.onSelectChange
      }
    },
    subTypeFilter () {
      return value => {
        if (value != null) {
          let result = this.subType.filter(e => e.code == value)
          if (result.length > 0) {
            return result[0].name
          } else {
            return ''
          }
        } else {
          return ''
        }
      }
    }
  },
  watch: {
    'filter.fashionerType': function (newVal, oldVal) {
      if (this.queryParam.fashionerType !== null) return
      this.queryParam.fashionerType = newVal.filter(e => e.default)[0].code || ''
      this.$refs.table.refresh()
    }
  },
  mounted () {
    console.log(this.subType)
  },
  methods: {
    // 会员详情
    handleDetail (record) {
      this.$router.push(`/box/customer/info/personal/${record.unionId}`)
    },
    // 弹窗
    showModal (value, type) {
      if (value) {
        this.modalVisible = value
        this.modalType = type
      } else {
      }
    },
    closeModal (value) {
      if (value) {
        this.modalVisible = false
        this.modalType = ''
      }
    },
    handleEdit (record) {
      this.visible = true
      this.mdl = { ...record }
    },
    onSelectChange (selectedRowKeys, selectedRows) {
      this.selectedRowKeys = selectedRowKeys
      this.selectedRows = selectedRows
    },
    onSearch (obj) {
      this.queryParam = obj
      this.$refs.table.refresh(true)
    },
    refreshList () {
      this.selectedRowKeys = []
      this.$refs.table.refresh()
    },
    fetchBatchStatus (arr) {
      let params = {
        requestData: {
          customerIds: arr
        }
      }
      return getFashionerSubStatus(params).then(res => {
        if (res.code == 0) {
          return res.data
        } else {
          return []
        }

      })
    }
  }
}